# Maintaiiner: Filipe Laíns (FFY00) <lains@archlinux.org>

pkgbase=python-meliae
_pkgname=${pkgbase#python-}
pkgname=(python-$_pkgname python2-$_pkgname)
pkgver=0.4.0
pkgrel=2
pkgdesc='Python Memory Usage Analyzer'
url='https://github.com/isaacl/meliae'
arch=('loong64' 'x86_64')
license=('GPL')
makedepends=('python-setuptools' 'python2-setuptools' 'cython' 'cython2')
source=("$url/archive/meliae-$pkgver.tar.gz"
        'fix-python3.patch::https://github.com/thehesiod/meliae/commit/993164289dd57c8670341ca0a1cc5b52e74bc21c.patch')
sha512sums=('1d88ecf082f4dabf2fd86f41453a97de976c68d7d9230046a39e16ed1b30b60c8c9245ecb3b1a187a80eabadbd5c1db2b2eede84f56da1c0b46237465e4f0a1d'
            '2310363ed702659a0b9f305808c66a693938ec192deabbd6aace6a5e85ceeec21102339c302395bdc9e21e59f6cd611ead8dd57f145d48a48df25950874b3697')

prepare() {
  cd $_pkgname-$_pkgname-$pkgver
  sed -i '/gitignore/d' ../fix-python3.patch
  patch -p1 < ../fix-python3.patch

  cp -a "$srcdir"/$_pkgname-$_pkgname-$pkgver{,-py2}
}

build() {
  echo "Building python-$_pkgname $pkgver"
  cd "$srcdir"/$_pkgname-$_pkgname-$pkgver
  python setup.py build

  echo "Building python2-$_pkgname $pkgver"
  cd "$srcdir"/$_pkgname-$_pkgname-$pkgver-py2
  python2 setup.py build
}

package_python-meliae() {
  depends=('python')
  cd $_pkgname-$_pkgname-$pkgver

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
}

package_python2-meliae() {
  depends=('python2')
  cd $_pkgname-$_pkgname-$pkgver-py2

  python2 setup.py install --root="$pkgdir" --optimize=1 --skip-build

  mv "$pkgdir"/usr/bin/strip_duplicates.py "$pkgdir"/usr/bin/strip_duplicates2.py
}

